import request from '@/utils/request'
import type { ICaseListReq, ICaseListResp, ICaseTableItem, IcaseResult } from '@/views/cases/type'

export async function getAllCases(data: ICaseListReq): Promise<ICaseListResp> {
  return await request({
    url: 'core/cases/getAllCases',
    method: 'post',
    data,
  }).then((res: any) => res.data)
}

export async function addCase(data: ICaseTableItem) {
  return await request({
    url: 'core/cases/addCase',
    method: 'post',
    data,
  })
}

export async function updateCase(data: ICaseTableItem) {
  return await request({
    url: 'core/cases/updateCase',
    method: 'post',
    data,
  })
}

export async function deleteCase(data: any) {
  return await request({
    url: 'core/cases/deleteCase',
    method: 'post',
    data,
  })
}

export async function getCases(data: any) {
  return await request({
    url: 'core/cases/getCases',
    method: 'post',
    data,
  }).then((res: any) => res.data.data)
}

export async function getCasesErrorHistory(data: string) {
  return await request({
    url: `core/cases/getCaseError/${data}`,
    method: 'get',
  }).then((res: any) => res.data)
}

export async function getAllDataset() {
  return await request({
    url: 'data/getAllDataset',
    method: 'post',
  }).then((res: any) => res.data)
}

export async function getUserDataset() {
  return await request({
    url: 'core/data/getAllDataset',
    method: 'post',
  }).then((res: any) => res.data)
}

export async function uploadDataSetFile(data: any) {
  return await request({
    url: 'core/file/uploadFile',
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    data,
  }).then((res: any) => res.data)
}

export async function getCaseResult(data: any): Promise<IcaseResult> {
  return await request({
    url: 'algo/pipeline',
    method: 'post',
    data,
  }).then((res: any) => res.data)
}

export async function runCase(data: any) {
  return await request({
    url: 'core/cases/runCase',
    method: 'post',
    data,
  }).then((res: any) => {
    if (res.code === 200)
      window.$message.success('The case has been run and is ready for calculation!')
  })
}

export async function getRawData(data: any) {
  return await request({
    url: 'core/result/getRawData',
    method: 'post',
    data,
  }).then((res: any) => res.data)
}

export async function getSampleCluster(data: any) {
  return await request({
    url: 'core/result/getSampleCluster',
    method: 'post',
    data,
  }).then((res: any) => res.data)
}

export async function getDrCluster(data: any) {
  return await request({
    url: 'core/result/getDrCluster',
    method: 'post',
    data,
  }).then((res: any) => res.data)
}

export async function getSom(data: any) {
  return await request({
    url: 'core/result/getSom',
    method: 'post',
    data,
  }).then((res: any) => res.data)
}

export async function getSensitivity(data: any) {
  return await request({
    url: 'core/result/getSensitivity',
    method: 'post',
    data,
  }).then((res: any) => res.data)
}

export async function getOptimization(data: any) {
  return await request({
    url: 'core/result/getOpt',
    method: 'post',
    data,
  }).then((res: any) => res.data)
}

export async function getContribution(data: any) {
  return await request({
    url: 'core/result/getContribution',
    method: 'post',
    data,
  }).then((res: any) => res.data)
}

export async function getHeatmap2d() {
  return await request({
    url: 'data/getHeatmap2d',
    method: 'post',
  })
}

export async function getHeatmap2dSom(data: any) {
  return await request({
    url: 'data/getHeatmap2dSom',
    method: 'post',
    data,
  }).then((res: any) => res.data)
}
